package org.example.sboot.controller;

import com.example.AjaxResult;
import com.example.core.controller.BaseController;
import com.example.page.TableDataInfo;
import io.swagger.annotations.Api;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.example.sboot.entity.Counlist;
import org.example.sboot.entity.Tabledata;
import org.example.sboot.service.CounlistService;
import org.example.sboot.service.TabledataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author jia
 * @date 2021/6/10
 */
@RestController
@RequestMapping("/test")
@Api(value = "Counlist", description = "8603条测试controller")
@Slf4j
public class CounlistController extends BaseController {

    @Autowired
    private CounlistService service;
    @Autowired
    private TabledataService tabledataService;


    @PostMapping("/getCounlist")
    public TableDataInfo getCounlist() {
        startPage();
        List<Counlist> list = service.selectByExample(null);
        return getDataTable(list);
    }

    @GetMapping("/getTableData")
    public TableDataInfo getTableData(Tabledata tabledata) {
        startPage();
        List<Tabledata> list = tabledataService.selectTabledataList(tabledata);
        return getDataTable(list);
    }


    @GetMapping("/getuser/{name}")
    public Map getuser(@PathVariable String name) throws UnsupportedEncodingException {
        Tabledata tabledata = tabledataService.selectTabledataByName(name);
        Map data=new HashMap();
        data.put("data", tabledata);
        return data;
    }
    @GetMapping("/getUserbyId/{id}")
    public Map getUserbyId(@PathVariable Integer id) throws UnsupportedEncodingException {
        Tabledata tabledata = tabledataService.selectByPrimaryKey(id);
        Map data=new HashMap();
        data.put("data", tabledata);
        return data;
    }

    @PostMapping("/addUser")
    public AjaxResult adduser(@RequestBody Tabledata tabledata) {
        return toAjax(tabledataService.insert(tabledata));
    }

    @PostMapping("/updateUser")
    public AjaxResult updateUser(@RequestBody Tabledata tabledata) {
        return toAjax(tabledataService.updateByExample(tabledata));
    }


    @GetMapping("/ssss")
    public String ssss() {
        System.out.println("CounlistController.ssss");
        return "ssss";
    }

    @DeleteMapping("/delUser/{Ids}")
    public AjaxResult remove(@PathVariable Long[] Ids)
    {
        return toAjax(tabledataService.deleteByPrimaryKey(Ids));
    }

}
